package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/tool"
	"group-card/model/entity"
	"group-card/rpc/sys/internal/svc"
	"group-card/rpc/sys/sysclient"
)

type CustomerAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCustomerAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CustomerAddLogic {
	return &CustomerAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CustomerAddLogic) CustomerAdd(in *sysclient.CustomerAddRequest) (*sysclient.CustomerAddResponse, error) {

	data := entity.SysCustomerReq{
		Name:          in.Name,
		MobilePhone:   in.MobilePhone,
		LandlinePhone: in.LandlinePhone,
		Area:          in.Area,
		Address:       in.Address,
		Email:         in.Email,
		BeginTimes:    tool.StringToTime(in.BeginTimes),
		EndTimes:      tool.StringToTime(in.EndTimes),
		Status:        in.Status,
	}

	var ctx context.Context
	_, err := l.svcCtx.CustomerModel.Insert(ctx, &data)

	if err != nil {
		return nil, err
	}

	return &sysclient.CustomerAddResponse{}, nil
}
